<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>跳舞功能测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            transition: background-color 0.5s ease;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: rgba(255, 255, 255, 0.95);
            padding: 30px;
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
            backdrop-filter: blur(10px);
        }
        .header {
            text-align: center;
            margin-bottom: 30px;
        }
        .header h1 {
            color: #333;
            font-size: 2.5em;
            margin: 0;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
        }
        .header p {
            color: #666;
            font-size: 1.2em;
            margin: 10px 0 0 0;
        }
        .main-content {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 30px;
            margin-bottom: 30px;
        }
        .render-area {
            width: 100%;
            height: 400px;
            border: 3px solid #333;
            border-radius: 15px;
            background: #87ceeb;
            overflow: hidden;
            position: relative;
        }
        .controls {
            display: flex;
            flex-direction: column;
            gap: 20px;
        }
        .dance-section {
            background: linear-gradient(135deg, #ff6b6b, #feca57);
            padding: 25px;
            border-radius: 15px;
            text-align: center;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }
        .dance-section h2 {
            color: white;
            margin: 0 0 20px 0;
            font-size: 1.8em;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
        }
        .dance-button {
            background: linear-gradient(45deg, #ff6b6b, #feca57);
            color: white;
            border: none;
            padding: 20px 40px;
            font-size: 1.5em;
            font-weight: bold;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        .dance-button:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(0,0,0,0.3);
        }
        .dance-button:active {
            transform: translateY(-1px);
        }
        .dance-button.dancing {
            animation: pulse 1s infinite;
            background: linear-gradient(45deg, #ff4757, #ffa502);
        }
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }
        .status-section {
            background: #f8f9fa;
            padding: 20px;
            border-radius: 15px;
            border-left: 5px solid #007bff;
        }
        .status-section h3 {
            color: #333;
            margin: 0 0 15px 0;
            font-size: 1.3em;
        }
        .status-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px 0;
            border-bottom: 1px solid #eee;
        }
        .status-item:last-child {
            border-bottom: none;
        }
        .status-label {
            font-weight: bold;
            color: #555;
        }
        .status-value {
            color: #007bff;
            font-weight: bold;
        }
        .status-value.dancing {
            color: #ff6b6b;
            animation: blink 1s infinite;
        }
        @keyframes blink {
            0%, 50% { opacity: 1; }
            51%, 100% { opacity: 0.3; }
        }
        .log-section {
            background: #2c3e50;
            color: #ecf0f1;
            padding: 20px;
            border-radius: 15px;
            max-height: 300px;
            overflow-y: auto;
            font-family: 'Courier New', monospace;
            font-size: 14px;
        }
        .log-section h3 {
            margin: 0 0 15px 0;
            color: #3498db;
        }
        .log-entry {
            margin: 5px 0;
            padding: 5px;
            border-radius: 5px;
            background: rgba(255,255,255,0.1);
        }
        .log-entry.info { border-left: 3px solid #3498db; }
        .log-entry.success { border-left: 3px solid #2ecc71; }
        .log-entry.warning { border-left: 3px solid #f39c12; }
        .log-entry.error { border-left: 3px solid #e74c3c; }
        .features {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            margin-top: 30px;
        }
        .feature-card {
            background: white;
            padding: 20px;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            text-align: center;
            transition: transform 0.3s ease;
        }
        .feature-card:hover {
            transform: translateY(-5px);
        }
        .feature-icon {
            font-size: 3em;
            margin-bottom: 15px;
        }
        .feature-card h3 {
            color: #333;
            margin: 0 0 10px 0;
        }
        .feature-card p {
            color: #666;
            margin: 0;
            line-height: 1.5;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🎵 跳舞功能测试</h1>
            <p>测试PixiCharacter SDK的独立跳舞动画系统</p>
        </div>

        <div class="main-content">
            <div class="render-area" id="renderArea">
                <!-- PixiJS渲染区域 -->
            </div>

            <div class="controls">
                <div class="dance-section">
                    <h2>💃 一键跳舞</h2>
                    <button class="dance-button" id="danceButton" onclick="toggleDance()">
                        🎵 开始跳舞
                    </button>
                </div>

                <div class="status-section">
                    <h3>📊 状态监控</h3>
                    <div class="status-item">
                        <span class="status-label">跳舞状态:</span>
                        <span class="status-value" id="danceStatus">停止</span>
                    </div>
                    <div class="status-item">
                        <span class="status-label">角色动画:</span>
                        <span class="status-value" id="characterStatus">空闲</span>
                    </div>
                    <div class="status-item">
                        <span class="status-label">背景动画:</span>
                        <span class="status-value" id="backgroundStatus">停止</span>
                    </div>
                    <div class="status-item">
                        <span class="status-label">换衣服:</span>
                        <span class="status-value" id="clothesStatus">停止</span>
                    </div>
                </div>

                <div class="log-section">
                    <h3>📝 实时日志</h3>
                    <div id="logContainer">
                        <div class="log-entry info">系统初始化完成</div>
                    </div>
                </div>
            </div>
        </div>

        <div class="features">
            <div class="feature-card">
                <div class="feature-icon">🎭</div>
                <h3>角色动画</h3>
                <p>自动执行旋转、跳跃、挥手、弹跳、摇晃等动画组合</p>
            </div>
            <div class="feature-card">
                <div class="feature-icon">🎨</div>
                <h3>背景动画</h3>
                <p>动态变换背景颜色，营造炫酷的舞蹈氛围</p>
            </div>
            <div class="feature-card">
                <div class="feature-icon">👕</div>
                <h3>换衣服</h3>
                <p>自动切换不同的服装，增加舞蹈的趣味性</p>
            </div>
            <div class="feature-card">
                <div class="feature-icon">⚡</div>
                <h3>独立模块</h3>
                <p>完全独立的跳舞系统，不影响核心SDK功能</p>
            </div>
        </div>
    </div>

    <!-- 引入PixiJS v7 -->
    <script src="https://pixijs.download/v7.4.0/pixi.min.js"></script>
    
    <!-- 引入PixiCharacter SDK -->
    <script src="https://unpkg.com/pixijs-character-ittantt-sdk@1.0.0/dist/pixijs-character-sdk.umd.js"></script>
    
    <!-- 引入跳舞动画模块 -->
    <script src="./dance-animation.js"></script>
    
    <script>
        let character = null;
        let danceAnimation = null;
        let isDancing = false;

        // 日志系统
        function log(message, type = 'info') {
            const logContainer = document.getElementById('logContainer');
            const timestamp = new Date().toLocaleTimeString();
            const logEntry = document.createElement('div');
            logEntry.className = `log-entry ${type}`;
            logEntry.innerHTML = `[${timestamp}] ${message}`;
            logContainer.appendChild(logEntry);
            logContainer.scrollTop = logContainer.scrollHeight;
            console.log(`[${type.toUpperCase()}] ${message}`);
        }

        // 更新状态显示
        function updateStatus(elementId, value, isActive = false) {
            const element = document.getElementById(elementId);
            element.textContent = value;
            element.className = `status-value ${isActive ? 'dancing' : ''}`;
        }

        // 初始化
        async function initialize() {
            try {
                log('开始初始化系统...', 'info');
                
                // 检查依赖
                if (!window.PIXI) {
                    throw new Error('PixiJS未找到');
                }
                if (!window.PixiJSCharacterSDK || !window.PixiJSCharacterSDK.PixiCharacter) {
                    throw new Error('PixiCharacter SDK未找到');
                }
                if (!window.DanceAnimation) {
                    throw new Error('DanceAnimation模块未找到');
                }

                log('所有依赖检查通过', 'success');

                // 创建角色
                const container = document.getElementById('renderArea');
                const PixiCharacter = window.PixiJSCharacterSDK.PixiCharacter;
                
                character = new PixiCharacter(container, {
                    width: 600,
                    height: 400,
                    body: './public/assets/body/body1.svg',
                    clothes: './public/assets/clothes/shirt1.svg',
                    hat: './public/assets/hats/hat1.svg',
                    leftHand: './public/assets/hands/left-hand.svg',
                    rightHand: './public/assets/hands/right-hand.svg',
                    leftHandPosition: { x: -5, y: 5 },
                    rightHandPosition: { x: 5, y: 5 },
                    onAnimationStart: (name) => {
                        log(`角色动画开始: ${name}`, 'info');
                        updateStatus('characterStatus', name, true);
                    },
                    onAnimationEnd: (name) => {
                        log(`角色动画结束: ${name}`, 'success');
                        updateStatus('characterStatus', '空闲');
                    },
                    onError: (error) => {
                        log(`角色错误: ${error}`, 'error');
                    }
                });

                log('角色创建成功', 'success');

                // 创建跳舞动画实例
                const clothesOptions = [
                    './public/assets/clothes/shirt1.svg',
                    './public/assets/clothes/shirt2.svg',
                    './public/assets/clothes/shirt3.svg'
                ];

                danceAnimation = new window.DanceAnimation(character, clothesOptions);
                log('跳舞动画模块初始化完成', 'success');

                // 设置状态监控
                setInterval(() => {
                    if (isDancing) {
                        updateStatus('backgroundStatus', '运行中', true);
                        updateStatus('clothesStatus', '运行中', true);
                    } else {
                        updateStatus('backgroundStatus', '停止');
                        updateStatus('clothesStatus', '停止');
                    }
                }, 1000);

                log('系统初始化完成！', 'success');
                updateStatus('danceStatus', '准备就绪');

            } catch (error) {
                log(`初始化失败: ${error.message}`, 'error');
                console.error(error);
            }
        }

        // 切换跳舞状态
        async function toggleDance() {
            if (!danceAnimation) {
                log('跳舞动画模块未初始化', 'error');
                return;
            }

            const button = document.getElementById('danceButton');

            if (!isDancing) {
                // 开始跳舞
                try {
                    await danceAnimation.startDance();
                    isDancing = true;
                    button.textContent = '🛑 停止跳舞';
                    button.classList.add('dancing');
                    updateStatus('danceStatus', '跳舞中', true);
                    log('开始跳舞！', 'success');
                } catch (error) {
                    log(`开始跳舞失败: ${error.message}`, 'error');
                }
            } else {
                // 停止跳舞
                try {
                    danceAnimation.stopDance();
                    isDancing = false;
                    button.textContent = '🎵 开始跳舞';
                    button.classList.remove('dancing');
                    updateStatus('danceStatus', '停止');
                    log('停止跳舞', 'info');
                } catch (error) {
                    log(`停止跳舞失败: ${error.message}`, 'error');
                }
            }
        }

        // 页面加载完成后初始化
        window.addEventListener('load', initialize);
    </script>
</body>
</html> 